Skip to content

perf(core): [SDK Overhead Reduction 6] Reduce JsonWriter stack allocation#5591

Draft
adinauer wants to merge 1 commit into
perf/sdk-overhead-reductionfrom
perf/sdk-overhead-reduction-json-writer-stack
Draft

perf(core): [SDK Overhead Reduction 6] Reduce JsonWriter stack allocation#5591
adinauer wants to merge 1 commit into
perf/sdk-overhead-reductionfrom
perf/sdk-overhead-reduction-json-writer-stack

Conversation

@adinauer

@adinauer adinauer commented Jun 22, 2026

Copy link
Copy Markdown
Member

PR Stack (SDK Overhead Reduction)


📜 Description

Reduce the initial nesting stack in the vendored JsonWriter from int[32] to int[8].

The stack still grows on demand through the existing push() logic when serializing deeply nested payloads.

💡 Motivation and Context

JsonWriter is created for envelope headers, item headers, and serialized payloads. Sentry SDK JSON is shallow in normal use, so the upstream GSON default stack size is larger than needed for the common path.

Starting with a smaller stack reduces per-writer allocation while preserving support for deeper JSON structures.

💚 How did you test it?

  • ./gradlew :sentry:test --tests io.sentry.vendor.gson.stream.JsonWriterTest
  • ./gradlew spotlessApply apiDump

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

#skip-changelog

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

Shrink the vendored JsonWriter nesting stack from 32 entries to 8 entries. The stack still grows on demand for deeply nested payloads, while common SDK serialization avoids the larger initial array allocation.

Co-Authored-By: Claude <noreply@anthropic.com>
@sentry

sentry Bot commented Jun 22, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.43.1 (1) release

⚙️ sentry-android Build Distribution Settings

@github-actions

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 362.91 ms 492.65 ms 129.74 ms
Size 0 B 0 B 0 B

@lbloder lbloder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants